package service;

import Dao.StudentDao;
import domain.Student;

public class StundetService {

    StudentDao studentDao = new StudentDao();

    public boolean add(Student stu) {

        return studentDao.add(stu);
    }

    public boolean isExists(String id) {

        Student[] stus = studentDao.findAll();
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null && stu.getId().equals(id)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Student[] findAll() {

        Student[] stus = studentDao.findAll();
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null){
                flag = true;
                break;
            }
        }
        if(flag){
            return stus;
        }else{
            return null;
        }
    }

    public void delete(String delId) {

        studentDao.delete(delId);
    }

    public void update(String updateId, Student newStu) {
        studentDao.update(updateId,newStu);
    }
}
